import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:magic_car/UI/update_dialog.dart';
import 'package:magic_car/jiance/car_body.dart';
import 'package:magic_car/jiance/car_info.dart';
import 'package:magic_car/jiance/index_Page.dart';
import 'package:magic_car/jiance/jiance_rec.dart';
import 'package:magic_car/jiance/jianceorder.dart';
import 'package:magic_car/jiance/testtab.dart';
import 'package:magic_car/jiance/uorder_page.dart';
import 'package:magic_car/user/acount.dart';
import 'package:magic_car/user/anserdetail.dart';
import 'package:magic_car/user/answer.dart';
import 'package:magic_car/user/answers.dart';
import 'package:magic_car/user/apply.dart';
import 'package:magic_car/user/contact.dart';
import 'package:magic_car/user/drawrec.dart';
import 'package:magic_car/user/examrec.dart';
import 'package:magic_car/user/login.dart';
import 'package:magic_car/user/moneydetail.dart';
import 'package:magic_car/user/regist.dart';
import 'package:magic_car/user/set.dart';
import 'package:magic_car/user/uppic.dart';
import 'package:magic_car/user/userinfo.dart';
import 'package:magic_car/user/uuserinfo.dart';
import 'package:magic_car/zhanshi/cheyuan_Page.dart';

/*
 * 有状态StatefulWidget
 *  继承于 StatefulWidget，通过 State 的 build 方法去构建控件
 */
class UBotomeMenumPage extends StatefulWidget {
  ////通过构造方法传值
  UBotomeMenumPage();

  //主要是负责创建state
  @override
  BotomeMenumPageState createState() => BotomeMenumPageState();
}

/*
 * 在 State 中,可以动态改变数据
 * 在 setState 之后，改变的数据会触发 Widget 重新构建刷新
 */
class BotomeMenumPageState extends State<UBotomeMenumPage> {
  BotomeMenumPageState();

  @override
  void initState() {
    ///初始化，这个函数在生命周期中只调用一次
    super.initState();
    // checkversion();
  }

  // //检查更新
  // checkversion() {
  //   _showUpdateDialog();
  // }

  // void _showUpdateDialog(content) {
  //   showDialog<void>(
  //       context: context,
  //       barrierDismissible: false,
  //       builder: (_) => UpdateDialog(content));
  // }

  @override
  Widget build(BuildContext context) {
    //构建页面
    return buildBottomTabScaffold();
  }

  //当前显示页面的
  int currentIndex = 0;

  //底部导航栏显示的内容
  final List<BottomNavigationBarItem> bottomNavItems = [
    BottomNavigationBarItem(
      backgroundColor: Colors.blue,
      icon: Image.asset('resource/images/jiance/jiance.png'),
      activeIcon: Image.asset('resource/images/jiance/jiance_sel.png'),
      title: Text("订单"),
    ),
    BottomNavigationBarItem(
      backgroundColor: Colors.blue[600],
      icon: Image.asset('resource/images/zhanshi/cheyuan.png'),
      activeIcon: Image.asset('resource/images/zhanshi/cheyuan_sel.png'),
      title: Text("问答"),
    ),
    BottomNavigationBarItem(
      backgroundColor: Colors.blue[800],
      icon: Image.asset('resource/images/baoxiu/baoxiu.png'),
      activeIcon: Image.asset('resource/images/baoxiu/baoxiu_sel.png'),
      title: Text("我的"),
    ),
  ];

  //点击导航项是要显示的页面
  final pages = [
    //IOrderPages(),
    IOrderPage(),
    AnswerPage(),
    UUserPage()

    // ChildItemView("首页"),
    // ChildItemView("发现"),
    // ChildItemView("动态"),
    // ChildItemView("我的")
  ];

  Widget buildBottomTabScaffold() {
    return
        // new MaterialApp
        // (
        //   debugShowCheckedModeBanner: false,
        //   title: '订单',
        //   home:
        new Scaffold(
      bottomNavigationBar: BottomNavigationBar(
        items: bottomNavItems,
        currentIndex: currentIndex,
        //所以一般都是使用fixed模式，此时，导航栏的图标和标题颜色会使用fixedColor指定的颜色，
        // 如果没有指定fixedColor，则使用默认的主题色primaryColor
        type: BottomNavigationBarType.fixed,
        //底部菜单点击回调
        onTap: (index) {
          _changePage(index);
        },
      ),
      //对应的页面
      body: pages[currentIndex],
    );
  }

  /*切换页面*/
  void _changePage(int index) {
    /*如果点击的导航项不是当前项  切换 */
    if (index != currentIndex) {
      setState(() {
        currentIndex = index;
      });
    }
  }
}
